

function validateFirst(cat) {
    
    var isValid = true;
    //RadioButton Type
    if (valButton($("input[name=catId]")) == null) {
        $("#TypeVal").attr('class',"field-validation-error");
        $("#catControl").addClass("error");
        isValid = false;
    }
    else {
        $("#TypeVal").attr('class',"field-validation-valid");
        $("#catControl").removeClass("error");
    }      
    //second fase
    if (isValid) { 
        
        //var type_id = VeicleTypeWrapper(cat);  
       
        fillVeicleModel(cat); 
        preloadAttr(cat);
        
        showPanel("addTruckSecond", "addTruckFirst");
        $("#progressBar").css("width","33%");
        $("#step").html("2");        
        $("#summaryStr").html(PostItemCategoryStr());
    }
    return isValid;
}
function backFirst() {   
    showPanel("addTruckFirst", "addTruckSecond");
    $("#progressBar").css("width","0%");
    $("#step").html("1");
    $("#summaryStr").html(PostItemCategoryStr());
}
function validateSecond() {
   
    var isValid = validateItemAttr();
    if (isValid) {
        showPanel("addTruckThird", "addTruckSecond"); 
        $("#progressBar").css("width","66%");
        $("#step").html("3");
        
        $("#summaryStr").html(PostItemTitleStr());
    }        
}
function backSecond() {
    showPanel("addTruckSecond", "addTruckThird");
    $("#progressBar").css("width","33%");
    $("#step").html("2");
    $("#summaryStr").html(PostItemTitleStr());
}
function validateThird() {
    var isValid = true;
    if (isValid) {	
        //Set title value
        var titleStr = ItemTitle();
        
        //var titleStr = $('#make option:selected').text() + ' - ' + $('#model option:selected').text();
                
        $('#titleId').val(titleStr);			
        if($('#descId').val() == '') $('#descId').val(' ');

        showPanel("addTruckFourth", "addTruckThird");  
        $("#progressBar").css("width","100%");	
        $("#step").html("4");
        
        if($("#price").val() != '') {           
            $("#summaryStr").html(PostItemAll());
        }
    }        
}
function backThird() {	
    if($('#descId').val() == ' ') $('#descId').val('');
    showPanel("addTruckThird", "addTruckFourth");
    $("#progressBar").css("width","66%");
    $("#step").html("3");
}


 function preloadAttr(idVehicleType) {     
       
     $("#mileagePnl").show();
     $("#fuelPnl").show();
     $("#emissionPnl").show();
     $("#vansweightPnl").show();
     $("#trailerweightPnl").show();
     $("#busweightPnl").show();
     $("#axlesPnl").show();
     $("#taxationPnl").show();
     $("#brakesPnl").show();
     $("#cabPnl").show();
     $("#buscabPnl").show();
     $("#seatsPnl").show();
     $("#bodytypePnl").show();
     $("#suspensionPnl").show();
     $("#payloadPnl").show();
     $("#trailertowbarPnl").show();
     $("#brandMan").show();
     $("#trailerType").hide();
     $("#busMan").hide();
//     if($("#descaux").val() == "")
//        $("#titleAuxPnl").hide();
     
     
 switch(idVehicleType) {
     case "1": //Van        
         $("#trailerweightPnl").hide();
         $("#busweightPnl").hide();
         $("#axlesPnl").hide();
         $("#brakesPnl").hide();
         $("#buscabPnl").hide();
         break;
     case "2": //Trailer
         $("#fuelPnl").hide();
         $("#emissionPnl").hide();
         $("#vansweightPnl").hide();
         $("#busweightPnl").hide();
         $("#taxationPnl").hide();
         $("#cabPnl").hide();
         $("#buscabPnl").hide();
         $("#seatsPnl").hide();
         $("#bodytypePnl").hide();
         $("#trailertowbarPnl").hide();
         $("#brandMan").hide();
         $("#trailerType").show();
         $("#mileagePnl").hide();
         break;
     case "3": //Bus        
         $("#vansweightPnl").hide();
         $("#trailerweightPnl").hide();
         $("#axlesPnl").hide();
         $("#brakesPnl").hide();
         $("#cabPnl").hide();
         $("#bodytypePnl").hide();
         $("#busMan").show();
         $("#brandMan").hide();
         break;
    } 
 }   

 
 function PostItemCategoryStr() {
     return $("input[name='catId']:checked").attr('id').replace('id_', '');
 }
 
 function PostItemTitleStr() {
     return PostItemCategoryStr() + " " + "<i class=\"icon-chevron-right\"></i> " + ItemTitle();
 }
 
 function PostItemAll() {
      return PostItemTitleStr() + " " + "<i class=\"icon-chevron-right\"></i> " + 
            $("#price").val() + " " + $("#currencySymbol").text();
 }
 
 function ItemTitle() {
     
     var titleStr = "";
        if($('#make option:selected').val() != -1 && $('#make option:selected').val() != "")
            titleStr += $('#make option:selected').text() + " - ";
        if ($('#model option:selected').val() != -1 && $('#model option:selected').val() != "")
            titleStr += $('#model option:selected').text();
        if ($('#descaux').val() != "")
            titleStr += $('#descaux').val();
        
     return titleStr;
 }
 
 function LoadAttrItemEdit()
 {
     if ($('#make option:selected').val() == -1 || $('#model option:selected').val() == -1)
     {
        if( $('#make option:selected').val() == -1)
        {
            $("#modelPnl").css("display","none");
        }
        $("#titleAuxPnl").css("display","");
        if($("#descaux").val() == "")  $("#descaux").val($('#titleId').val());
    }
 }
 
 function validateItemAttr() {
   
    var isValid = true;
    
    if($("#makePnl").css("display") != "none")
    {
        var makeIsValid = text_validation($("#make"));
        if(!makeIsValid) { isValid = false; $("#make").focus(); }
        else removeError($("#make"));
    }
    
    var regIsValid = text_validation($("#registration"));
    if(!regIsValid) { isValid = false; $("#registration").focus(); }
    else removeError($("#registration"));
    
    var insIsValid = text_validation($("#inspection"));
    if(!insIsValid) { isValid = false; $("#inspection").focus(); }
    else removeError($("#inspection"));
    
    if($("#modelPnl").css("display") != "none")
    {
        var modelIsValid = text_validation($("#model"));
        if(!modelIsValid) { isValid = false; $("#model").focus(); }
        else removeError($("#model"));
    }
    if($("#titleAuxPnl").css("display") != "none")
    {
       var titleAuxIsValid = text_validation($("#descaux"));
        if(!titleAuxIsValid) { isValid = false; $("#descaux").focus(); }
        else removeError($("#descaux"));     
    }
    
    if($("#mileagePnl").css("display") != "none")
    {
        var kmIsValid = text_validation($("#mileage"));
        if(!kmIsValid) { isValid = false; $("#mileage").focus(); }
        else removeError($("#mileage"));
    }
    
    if($("#vansweightPnl").css("display") != "none")
    {
        var vansWeightIsValid = text_validation($("#vansweight"));
        if(!vansWeightIsValid) { isValid = false; $("#vansweight").focus(); }
        else removeError($("#vansweight"));     
    }
    
    if($("#trailerweightPnl").css("display") != "none")
    {
        var trailerWeightIsValid = text_validation($("#trailerweight"));
        if(!trailerWeightIsValid) { isValid = false; $("#trailerweight").focus(); }
        else removeError($("#trailerweight"));     
    }
    
    if($("#busweightPnl").css("display") != "none")
    {
        var busWeightIsValid = text_validation($("#busweight"));
        if(!busWeightIsValid) { isValid = false; $("#busweight").focus(); }
        else removeError($("#busweight"));     
    }
    
    if($("#taxationPnl").css("display") != "none")
    {
        var taxIsValid = text_validation($("#taxation"));
        if(!taxIsValid) { isValid = false; $("#taxation").focus(); }
        else removeError($("#taxation"));     
    }
    
    if($("#bodytypePnl").css("display") != "none")
    {
        var bodyIsValid = text_validation($("#bodytype"));
        if(!bodyIsValid) { isValid = false; $("#bodytype").focus(); }
        else removeError($("#bodytype"));     
    }
    
    if($("#axlesPnl").css("display") != "none")
    {
        var axlesIsValid = text_validation($("#axles"));
        if(!axlesIsValid) { isValid = false; $("#axles").focus(); }
        else removeError($("#axles"));     
    }
    
    if($("#buscabPnl").css("display") != "none")
    {
        var buscabIsValid = text_validation($("#buscab"));
        if(!buscabIsValid) { isValid = false; $("#buscab").focus(); }
        else removeError($("#buscab"));     
    }
    
    return isValid;
 }